package com.example.demo.config.rabbitMq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class XdelayConfig {

    public static final String DELAY_EXCHANGE = "delay_exchange_expert";
    public static final String DELAY_KEY = "delay_key_expert";
    public static final String DELAY_QUEUE = "delay_queue_expert";
    
    public static final String DELAY_EXCHANGE2 = "delay_exchange_expert2";
    public static final String DELAY_KEY2 = "delay_key_expert2";
    public static final String DELAY_QUEUE2 = "delay_queue_expert2";

    /**
     * 延时队列交换机
     * 注意这里的交换机类型：CustomExchange
     *
     * @return
     */
    @Bean
    public CustomExchange delayExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange(DELAY_EXCHANGE, "x-delayed-message", true, false, args);
    }
    @Bean
    public CustomExchange delayExchange2() {
    	Map<String, Object> args = new HashMap<>();
    	args.put("x-delayed-type", "direct");
    	return new CustomExchange(DELAY_EXCHANGE2, "x-delayed-message", true, false, args);
    }

    /**
     * 延时队列
     *
     * @return
     */
    @Bean
    public Queue delayQueue() {
        return new Queue(DELAY_QUEUE, true);
    }
    @Bean
    public Queue delayQueue2() {
    	return new Queue(DELAY_QUEUE2, true);
    }

    /**
     * 给延时队列绑定交换机
     *
     * @return
     */
    @Bean
    public Binding cfgDelayBinding() {
        return BindingBuilder.bind(delayQueue()).to(delayExchange()).with(DELAY_KEY).noargs();
    }
    @Bean
    public Binding cfgDelayBinding2() {
        return BindingBuilder.bind(delayQueue2()).to(delayExchange2()).with(DELAY_KEY2).noargs();
    }
}
